<template>
	<view class="box">
		<view class="top">
			<view class="input">
				<u-search v-model="keyword" :show-action="true" placeholder="请输入搜索内容" actionText="搜索" :animation="true"
					:clearabled="true" :focus="true" @change="changeKeyword" @search="goResult(keyword)"
					@custom="goResult(keyword)"></u-search>
			</view>
			<view class="lenovo" v-if="lenovoData.length>0">
				<view v-for="(item,index) of lenovoData" :key="index" @click="goResult(item.store_name)">
					{{item.store_name}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '', //
				lenovoData: [], //联想数据
				id: 0,
			}
		},
		watch: {
			keyword(n, o) {

				if (n == '') {
					this.lenovoData = [];
				}
			}
		},
		onLoad(options) {
			this.id = options.id
			if (options.keyword) {
				this.keyword = options.keyword;
			}
		},
		methods: {
			// 监听搜索内容
			changeKeyword(e) {
				console.log('改变', e);
				let data = {
					keyword: e,
					page: 1,
					limit: 10,
					// mar_id:this.id  //要求搜索时为整个商城商品
				}
				this.$request('product/spu/lst', data, 'GET').then(res => {
					this.lenovoData = res.data.list
				})


			},
			// 搜索结果
			goResult(value) {

				uni.navigateTo({
					url: '/pages/client/search-result/search-result?keyword=' + value + '&id=' + this.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		.top {
			.input {
				padding: 30rpx 20rpx;
			}

			.lenovo {
				&>view {
					padding: 26rpx 20rpx;
					border-bottom: 1rpx solid #eee;
				}
			}
		}

	}
</style>
